package com.api.hg.util;

import jxl.read.biff.Record;
import weaver.conn.RecordSet;
import weaver.general.Util;

/**
 * 盘点转换类
 *
 */
public class DisTranceUtil {
    private String swformid="-198";
    private String swmodeid="102";
    private String swcustomid="93";

    private String gbformid="-197";
    private String gbmodeid="101";
    private String gbcustomid="92";

//com.api.hg.util.TranceUtil.getSwTitle
    public String getSwTitle(String title,String id){
        String url="<a title=\""+title+"\" href=\"javascript:void(0)\" onclick=\"javaScript:window.open('/spa/cube/index.html#/main/cube/card?type=0&modeId="+swmodeid+"&formId="+swformid+"&billid="+id+"&opentype=2&customid="+swcustomid+"&viewfrom=fromsearchlist&dbviewtype=3')\" class=\"autoWrap\">"+title+"</a>";
        return url;
    }
    //com.api.hg.util.TranceUtil.getGbTitle
    public String getGbTitle(String title,String id){
        String url="<a title=\""+title+"\" href=\"javascript:void(0)\" onclick=\"javaScript:window.open('/spa/cube/index.html#/main/cube/card?type=0&modeId="+gbmodeid+"&formId="+gbformid+"&billid="+id+"&opentype=2&customid="+gbcustomid+"&viewfrom=fromsearchlist&dbviewtype=3')\" class=\"autoWrap\">"+title+"</a>";
        return url;
    }
    /*
        获取人名
     */
    public String getHrmLastname(String userid){
        String lastname="";
        userid= Util.null2String(userid).trim();
        if("".equals(userid)){
            return "";
        }
        if("1".equals(userid)){
            return "系统管理员";
        }
        if(userid.endsWith(",")){
            userid=userid.substring(0,userid.length()-1);
        }
        RecordSet re=new RecordSet();
        String sql="select * from hrmresource where id in ("+userid+")";
        re.execute(sql);
        while(re.next()){
            String str=Util.null2String(re.getString("lastname")).trim();
            if("".equalsIgnoreCase(str)){
                continue;
            }
            lastname=lastname+str+",";
        }
        return lastname;
    }

    /**
     * 根据类型获取 部门 科室的名称
     * @param dataid 数据id
     * @param type 类型
     * @return
     */
    public String getSubOrDep(String dataid,String type){
        dataid= Util.null2String(dataid).trim();
        type= Util.null2String(type).trim();
        if("".equals(dataid)||"".equals(type)){
            return "";
        }
        String lastname="";
        if(dataid.endsWith(",")){
            dataid=dataid.substring(0,dataid.length()-1);
        }
        RecordSet re=new RecordSet();
        String sql="";
        if("0".equals(type)||"1".equals(type)){//部门
            sql="select SubCompanyname name from HrmSubCompany where id in ("+dataid+")";
        }
        if("2".equals(type)){//科室
            sql="select Departmentname name from HrmDepartment where id in ("+dataid+")";
        }
        re.execute(sql);
        while(re.next()){
            String name=Util.null2String(re.getString("name")).trim();
            if(!"".equals(name)){
                lastname=lastname+name+",";
            }
        }
        if(lastname.endsWith(",")){
            lastname=lastname.substring(0,lastname.length()-1);
        }
        return lastname;
    }
    public String getSblxDesc(String sblx){
        sblx= Util.null2String(sblx).trim();
        if("".equals(sblx)){
            return "";
        }
        if(sblx.endsWith(",")){
            sblx=sblx.substring(0,sblx.length()-1);
        }
        String sblcdesc="";
        RecordSet re=new RecordSet();
        String sql="select id,flmc from uf_sbflxx where id in ("+sblx+")";
        re.execute(sql);
        while(re.next()){
            String flmc=Util.null2String("flmc").trim();
            if(!"".equals(flmc)){
                sblcdesc=sblcdesc+flmc+",";
            }
        }
        if(sblcdesc.endsWith(",")){
            sblcdesc=sblcdesc.substring(0,sblcdesc.length()-1);
        }
        return sblcdesc;
    }

    /**
     * 获取待盘点数量
     * @param data 列值
     * @param dataid 数据ID
     * @return
     */
    public String waitingDiscoveryCount(String data,String dataid){
        String couts="";
        dataid=Util.null2String(dataid).trim();
        if("".equals(dataid)||dataid.indexOf("_")<=0){
            return "";
        }
        RecordSet re=new RecordSet();
        String type=dataid.substring(0,dataid.indexOf("_"));
        String id=dataid.substring(dataid.indexOf("_")+1);
        String sql=" ";
        if("all".equals(type)){
            sql="select count(1) counts from uf_grzcpdjl where szglypdrw="+id+" and isnull(sfyx,-1) in (0,-1) and isnull(sfkspd,-1) in (-1,0,2,3)";
        }
        if("sub".equals(type)){
            sql="select count(1) counts from uf_grzcpdjl where szbmpdrw="+id+" and isnull(sfyx,-1) in (0,-1) and isnull(sfkspd,-1) in (-1,0,2,3)";
        }
        if("dep".equals(type)){
            sql="select count(1) counts from uf_grzcpdjl where szkspdrw="+id+" and isnull(sfyx,-1) in (0,-1) and isnull(sfkspd,-1) in (-1,0,2,3)";
        }
        re.execute(sql);
        if(re.next()){
            couts=Util.null2String(re.getString("counts")).trim();
        }
        return couts;
    }
    /**
     * 获取已经盘点数量
     * @param data 列值
     * @param dataid 数据ID
     * @return
     */
    public String DiscoveryCount(String data,String dataid){
        String couts="";
        dataid=Util.null2String(dataid).trim();
        if("".equals(dataid)||dataid.indexOf("_")<=0){
            return "";
        }
        RecordSet re=new RecordSet();
        String type=dataid.substring(0,dataid.indexOf("_"));
        String id=dataid.substring(dataid.indexOf("_")+1);
        String sql=" ";
        if("all".equals(type)){
            sql="select count(1) counts from uf_grzcpdjl where szglypdrw="+id+" and isnull(sfyx,-1) in (0,-1) and isnull(pdzt,-1) in (1)";
        }
        if("sub".equals(type)){
            sql="select count(1) counts from uf_grzcpdjl where szbmpdrw="+id+" and isnull(sfyx,-1) in (0,-1) and isnull(pdzt,-1) in (1)";
        }
        if("dep".equals(type)){
            sql="select count(1) counts from uf_grzcpdjl where szkspdrw="+id+" and isnull(sfyx,-1) in (0,-1) and isnull(pdzt,-1) in (1)";
        }
        re.execute(sql);
        if(re.next()){
            couts=Util.null2String(re.getString("counts")).trim();
        }
        return couts;
    }

    /*
        获取下拉框的值
        字段名称  @field
        表名     @tablename
        值      @value
     */
    public String getSelectnameByValue(String value,String tablename,String field){
        String selectname="";
        RecordSet re=new RecordSet();
        String sql="select c.selectname from workflow_bill a,workflow_billfield b,workflow_selectitem c where a.id=b.billid and a.tablename='"+tablename+"'" +
                " and b.id=c.fieldid and b.fieldname='"+field+"' and c.selectvalue='"+value+"'";
        re.execute(sql);
        while(re.next()){
            selectname=Util.null2String(re.getString("selectname"));
        }
        return selectname;
    }
}
